Stacked bar chart
Contents
Stacked bar chart#
Setup#
import pandas as pd
import altair as alt
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
alt.data_transformers.disable_max_rows()
DataTransformerRegistry.enable('default')
Data#
ROOT = "https://raw.githubusercontent.com/kirenz/datasets/master/"
DATA = "loans.csv"
df = pd.read_csv(ROOT + DATA)
df.homeownership = df.homeownership.astype("category")
df.application_type = df.application_type.astype("category")
Chart#
chart = alt.Chart(df).mark_bar().encode(
x=alt.X('homeownership',
sort='-y',
axis=alt.Axis(title="Homeownership",
titleAnchor="start",
labelAngle=0)),
y=alt.Y('count(homeownership)',
axis=alt.Axis(title = "Count",
titleAnchor="end")),
color= ___.___('___',
legend=alt.Legend(title="Type"))
).properties(
title='This is a stacked bar chart',
width=350,
height=150
)
chart